#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

struct Event {
    int time, status;

    bool operator < (const Event & e1 ) const {
        return time < e1.time;
    }
};

int n, m;

int get(vector<Event> & ets) {
    int res = 0;
    for (int i = 0; i < ets.size(); i += 2) 
        res += ets[i + 1].time - ets[i].time;
    return res;
}

inline void solution() {
    scanf("%d%d", &n, &m);
    unordered_map<string, vector<Event>> cars;
    // 将所有车的信息归成一块
    char id[10], status[10];
    for (int i = 0; i < n; i ++ ) {
        int h, m, s;
        scanf("%s %d:%d:%d %s", id, &h, &m, &s, status);
        int time = h * 3600 + m * 60 + s;
        int st = 0;
        if (status[0] == 'o') st = 1;
        cars[id].push_back({time, st});
    }

    vector<Event> events;
    for (auto& item : cars) {
        auto& ets = item.second;
        sort(ets.begin(), ets.end());
        int k = 0;
        for (int i = 0; i < ets.size(); i ++ ) 
            if (ets[i].status == 0 && i + 1 < ets.size() && ets[i + 1].status == 1)
                ets[k ++ ] = ets[i], ets[k ++ ] = ets[i + 1], i ++ ;
        ets.erase(ets.begin() + k, ets.end());
        for (int i = 0; i < ets.size(); i ++ ) events.push_back(ets[i]);
    }

    sort(events.begin(), events.end());
    int k = 0, sum = 0;
    while (m -- ) {
        int h, m, s;
        scanf("%d:%d:%d", &h, &m, &s);
        int t = h * 3600 + m * 60 + s;
        while (k < events.size() && events[k].time <= t) {
            if (events[k].status == 0) sum ++ ;
            else sum -- ;
            k ++ ;
        }
        printf("%d\n", sum);
    }

    int maxt = 0;
    vector<string> cid;
    for (auto& item : cars) {
        int t = get(item.second);
        if (maxt < t) {
            cid.clear();
            cid.push_back(item.first);
            maxt = t;
        }    
        else if (maxt == t)
            cid.push_back(item.first);
    }
    sort(cid.begin(), cid.end());
    printf("%s", cid[0].c_str());
    for (int i = 1; i < cid.size(); i ++ ) 
        printf(" %s", cid[i].c_str());
    printf(" %02d:%02d:%02d", maxt / 3600, maxt % 3600 / 60, maxt % 60);
    printf("\n");
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}